package org.kernely.ui.mvp;

import java.util.HashMap;
import java.util.Set;
import java.util.Map.Entry;

import org.kernely.security.persistence.Role;

public class KernelyBundleMenu {
	private HashMap<String, Class<? extends IKernelyView>> menuViews = new HashMap<String, Class<? extends IKernelyView>>();
	private HashMap<Class<? extends IKernelyView>, Set<String>> viewsRoles = new HashMap<Class<? extends IKernelyView>, Set<String>>();
	
	
	/**
	 * Associates the specified view with the specified menu name. If the menu previously contained a mapping for this name, the old view is replaced.
	 * Sub-menus added by this method will be accessible by all users.
	 * @param menuName The name which the specified view is to be associated.
	 * @param view The view to be associated to the specified name.
	 */
	public final void put(String menuName, Class<? extends IKernelyView> view) {
		this.put(menuName, view,null);
	}
	
	/**
	 * Associates the specified view with the specified menu name and the specified roles authorized to see this menu. If the menu previously contained a mapping for this name, the old view is replaced.
	 * @param menuName The name which the specified view is to be associated.
	 * @param view The view to be associated to the specified name.
	 * @param roles A set containing all the roles which are authorized to see the menu.
	 */
	public final void put(String menuName, Class < ? extends IKernelyView> view, Set<String> roles){
		menuViews.put(menuName, view);
		viewsRoles.put(view, roles);
	}
	
	/**
	 * Returns a collection of the views contained in the menu.
	 * Each element in the returned collection is a Map.Entry.
	 * @return 
	 * @return a collection of the mappings name / view contained in menu.
	 */
	public final Set<Entry<String, Class<? extends IKernelyView>>> entrySet(){
		return menuViews.entrySet();
	}
	
	public final Set<String> getRoles(Class<? extends IKernelyView> view){
		return viewsRoles.get(view);
	}
}
